package com.diyizu.controller;

import com.diyizu.domain.Student;
import com.diyizu.factory.Factory;
import com.diyizu.service.IStudentInfoService;
import com.diyizu.service.impl.StudentInfoServiceImpl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class StatisticalReportController {
    IStudentInfoService sti= Factory.getStudentInfoService();
    public void stuTongJi() {
        ArrayList<Student> list = sti.findAllStudents();
        System.out.println("当前系统总共有" + list.size() + "学生");
        System.out.println("当前男生有" + list.stream().filter (student -> student.getSex().equals("男")).count() + "人");
        System.out.println("当前女生有" + list.stream().filter (student -> student.getSex().equals("女")).count() + "人");
        System.out.println("年龄为18岁的学生有：" + list.stream().filter (student -> student.getAge() == 18).count() + "人");
        System.out.println("年龄为19岁的学生有：" + list.stream().filter (student -> student.getAge() == 19).count() + "人");
        System.out.println("年龄为20岁的学生有：" + list.stream().filter (student -> student.getAge() == 20).count() + "人");
        long l1 = list.stream().filter(student -> student.getClasses().equals("201班")).count();
        System.out.println("201班人数为：" + l1 + "人");
        List<Student> collect = list.stream().filter(student -> student.getClasses().equals("201班")).collect(Collectors.toList());
        int age = 0;
        for (Student student : collect) {
            age += student.getAge();
        }
        System.out.println("201班平均年龄为" + (int) (age / l1) + "岁");
        HashSet<Student> students = new HashSet<>(list);
        System.out.println("201班中共有" + students.size() + "个分组");
        for (Student student : students) {
            System.out.println("第" + student.getGroup() + "组:" + list.stream().filter(student1 -> student1.getGroup() == student.getGroup()).count() + "人 ");
        }
    }
}